package cn.ecut.contoller;

import cn.ecut.model.User;
import cn.ecut.service.IuserInterface;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;
import java.util.ArrayList;

@Controller()
@RequestMapping("/admin/user")
public class UserController {
    @Autowired
    private IuserInterface iuserInterface;

    @RequestMapping("/query")
    private String queryUserList(HttpServletRequest request) {
//        List<User> userList = iuserInterface.queryUserList();
        ArrayList<User> userList = new ArrayList<>();
        User user1 = new User();
        user1.setUsername("8888");
        userList.add(user1);

        request.setAttribute("userList", userList);
        for (User user : userList) {
            System.out.println(user);
        }
        return "hello";
    }

    @RequestMapping("/userlogin")
    public String loginUser(HttpServletRequest request, String userName, String userPassword) {
        System.out.println(userName);
        System.out.println(userPassword);
        User user = iuserInterface.loginUser(userName, userPassword);
        if (user != null) {
            request.getSession().setAttribute("user", user);
            return "error";
        } else {
            request.setAttribute("msg", "账号名或密码错误");
            return "userLogined";
        }
    }

}
